///////////////////////////////////////////////////////////////////////////
// Copyright © 2014 - 2018 Esri. All Rights Reserved.
//
// Licensed under the Apache License Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////////

define([
  'dojo/_base/declare',
  'dojo/_base/html',
  'dojo/query',
  'dojo',
  'dojo/aspect',
  'dojo/on',
  'dojo/dom',
  'dojo/dom-style',
  'dojo/_base/Color',
  'dojo/_base/lang',
  'dojo/_base/xhr',
  'dojo/_base/array',
  'dojo/dom-construct',
  'dojo/_base/json',
  'dojo/data/ItemFileWriteStore',
  'dojox/grid/DataGrid',
  'esri/toolbars/draw',
  'esri/graphic',
  'esri/layers/GraphicsLayer',
  "esri/layers/ArcGISDynamicMapServiceLayer",
  'esri/symbols/SimpleLineSymbol',
  'esri/symbols/SimpleFillSymbol',
  'esri/symbols/SimpleMarkerSymbol',
  'esri/symbols/PictureMarkerSymbol',
  'esri/geometry/Point',
  'esri/geometry/Multipoint',
  'esri/geometry/Polygon',
  'esri/geometry/Extent',
  'esri/SpatialReference',
  "esri/dijit/Popup", "esri/dijit/PopupTemplate",


  "esri/tasks/query", "esri/tasks/QueryTask",

  'dijit/_WidgetsInTemplateMixin',
  'dijit/layout/TabContainer',
  'dijit/layout/ContentPane',
  'dijit/form/Button',
  'dijit/registry',
  'jimu/BaseWidget',
  'jimu/dijit/Message',
  'jimu/dijit/AppStatePopup',
  'libs/echarts/echarts',
  'libs/proj4js/dist/proj4',

],
  function (declare, html, query, dojo, aspect, on, dom, domStyle, Color, lang, xhr, array, domConstruct, json,
    ItemFileWriteStore, DataGrid, Draw, Graphic, GraphicsLayer, ArcGISDynamicMapServiceLayer, SimpleLineSymbol, SimpleFillSymbol,
    SimpleMarkerSymbol, PictureMarkerSymbol,Point, Multipoint, Polygon, Extent,SpatialReference,Popup,PopupTemplate, Query, QueryTask,
    _WidgetsInTemplateMixin, TabContainer,
    ContentPane, Button, registry, BaseWidget, Message, AppStatePopup, echarts, proj4) {
    var clazz = declare([BaseWidget], {
      baseClass: "jimu-widget-scalebar",
      name: "爆管分析",
      mylayer: null,
      count:0,

      moveTopOnActive: false,
      postCreate: function () {
        this.inherited(arguments)
      },
      startup: function() {
        var config = this.config;
        // 1. 随机的生成一些点在图上
        // 2. 也可以自己指定点
        this.mylayer = new GraphicsLayer();
        let symbol = new PictureMarkerSymbol('/images/green.png', 20, 25);

        this.config.points.forEach(item=>{
          this.mylayer.add(new Graphic(new Point(item), symbol,item.attributes))
        })
        this.mylayer.setInfoTemplate(new PopupTemplate({
          title: "爆管详情",
          description: `<div>生产年份:{yearStart}</div>
                        <div>最近检修:{Percent_Fi}</div>
                        <div>公司:{company}</div>
                        <div>现场图片:</div>
                        <div><img src={image} /></div>`
        }))
        this.map.addLayer(this.mylayer)

      },

      onClose: function() {
        if(this.count === 0){
        }else if(this.count%2 === 0){
          this.startup();
        }else{
          this.mylayer.clear()
          this.map.removeLayer(this.mylayer)
        }
        this.count++;
      }
    });

    return clazz;
  });